﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatTinhChat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaTinhChat();

            layTenTinhChat();
        }
    }

    protected void layMaTinhChat()
    {
        string maTinhChatURL = Request.QueryString["MaTinhChat"];

        TinhChatBUS tcBUS = new TinhChatBUS();

        string maTinhChat = tcBUS.layMaTinhChat(maTinhChatURL);

        txtMaTinhChat.Text = maTinhChat;
    }

    protected void layTenTinhChat()
    {
        string maTinhChatURL = Request.QueryString["MaTinhChat"];

        TinhChatBUS tcBUS = new TinhChatBUS();

        string tenTinhChat = tcBUS.layTenTinhChat(maTinhChatURL);

        txtTenTinhChat.Text = tenTinhChat;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            TinhChat tcDTO = new TinhChat();
            tcDTO.MaTinhChat = txtMaTinhChat.Text.ToUpper();
            tcDTO.TenTinhChat = txtTenTinhChat.Text.ToUpper();

            //Kiem tra rong
            if (tcDTO.MaTinhChat.ToString() == string.Empty)
            {
                Alert.Show("Ma tinh chat khong duoc rong");
                return;
            }

            if (tcDTO.TenTinhChat.ToString() == string.Empty)
            {
                Alert.Show("Ten tinh chat khong duoc rong");
                return;
            }

            //Sua
            if (tcDTO.MaTinhChat.ToString() != string.Empty && tcDTO.TenTinhChat.ToString() != string.Empty)
            {
                TinhChatBUS tcBUS = new TinhChatBUS();

                string maTinhChatURL = Request.QueryString["MaTinhChat"];

                tcBUS.suaTinhChat(tcDTO, maTinhChatURL);

                Response.Redirect("ThamSoVanBan.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoVanBan.aspx");
    }
}